<template>
  <a-modal 
    v-model:open="visible" 
    :footer="null" 
    width="600px"
    class="app-detail-modal"
    :mask-style="{ backdropFilter: 'blur(8px)' }"
  >
    <template #title>
      <div class="modal-title">
        <span class="title-icon">📱</span>
        <span>应用详情</span>
      </div>
    </template>
    <div class="app-detail-content">
      <!-- 应用基础信息 -->
      <div class="app-basic-info">
        <div class="info-section">
          <div class="section-title">
            <span class="section-icon">ℹ️</span>
            <span>基本信息</span>
          </div>
          <div class="info-grid">
            <div class="info-item">
              <div class="info-label">
                <span class="label-icon">👤</span>
                <span>创建者</span>
              </div>
              <div class="info-value">
                <UserInfo :user="app?.user" size="small" />
              </div>
            </div>
            <div class="info-item">
              <div class="info-label">
                <span class="label-icon">📅</span>
                <span>创建时间</span>
              </div>
              <div class="info-value">
                <span class="time-text">{{ formatTime(app?.createTime) }}</span>
              </div>
            </div>
          </div>
        </div>
      </div>

      <!-- 操作栏（仅本人或管理员可见） -->
      <div v-if="showActions" class="app-actions">
        <div class="actions-title">
          <span class="actions-icon">⚙️</span>
          <span>操作</span>
        </div>
        <div class="actions-buttons">
          <a-button type="primary" @click="handleEdit" class="action-btn edit-btn">
            <template #icon>
              <EditOutlined />
            </template>
            编辑应用
          </a-button>
          <a-popconfirm
            title="确定要删除这个应用吗？"
            @confirm="handleDelete"
            ok-text="确定"
            cancel-text="取消"
            placement="topRight"
          >
            <a-button danger class="action-btn delete-btn">
              <template #icon>
                <DeleteOutlined />
              </template>
              删除应用
            </a-button>
          </a-popconfirm>
        </div>
      </div>
    </div>
  </a-modal>
</template>

<script setup lang="ts">
import { computed } from 'vue'
import { EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import UserInfo from './UserInfo.vue'
import { formatTime } from '@/utils/time'

interface Props {
  open: boolean
  app?: API.AppVO
  showActions?: boolean
}

interface Emits {
  (e: 'update:open', value: boolean): void
  (e: 'edit'): void
  (e: 'delete'): void
}

const props = withDefaults(defineProps<Props>(), {
  showActions: false,
})

const emit = defineEmits<Emits>()

const visible = computed({
  get: () => props.open,
  set: (value) => emit('update:open', value),
})

const handleEdit = () => {
  emit('edit')
}

const handleDelete = () => {
  emit('delete')
}
</script>

<style scoped>
/* 动画变量 */
:root {
  --animation-duration-fast: 0.2s;
  --animation-duration-normal: 0.3s;
  --animation-duration-slow: 0.5s;
  --animation-easing: cubic-bezier(0.4, 0, 0.2, 1);
}

/* 动画定义 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* 模态框标题样式 */
.modal-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 18px;
  font-weight: 700;
  color: #1a202c;
}

.title-icon {
  font-size: 20px;
}

/* 内容容器样式 */
.app-detail-content {
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* 基础信息区域 */
.app-basic-info {
  margin-bottom: 32px;
}

.info-section {
  background: rgba(248, 250, 252, 0.6);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  animation: fadeInUp 0.6s var(--animation-easing);
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(99, 102, 241, 0.1);
}

.section-icon {
  font-size: 18px;
}

.info-grid {
  display: grid;
  gap: 16px;
}

.info-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 12px;
  border: 1px solid rgba(226, 232, 240, 0.6);
  transition: all var(--animation-duration-normal) var(--animation-easing);
  animation: slideInRight 0.5s var(--animation-easing);
}

.info-item:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(99, 102, 241, 0.3);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.info-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #4b5563;
  min-width: 120px;
}

.label-icon {
  font-size: 16px;
}

.info-value {
  flex: 1;
  text-align: right;
}

.time-text {
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
}

/* 操作区域样式 */
.app-actions {
  background: rgba(248, 250, 252, 0.6);
  border-radius: 16px;
  padding: 24px;
  border: 1px solid rgba(226, 232, 240, 0.8);
  animation: fadeInUp 0.6s var(--animation-easing) 0.1s both;
}

.actions-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid rgba(239, 68, 68, 0.1);
}

.actions-icon {
  font-size: 18px;
}

.actions-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.action-btn {
  height: 40px;
  padding: 0 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  transition: all var(--animation-duration-normal) var(--animation-easing);
  border: none;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.edit-btn {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  color: white;
}

.edit-btn:hover {
  background: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.3);
}

.delete-btn {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
}

.delete-btn:hover {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(239, 68, 68, 0.3);
}

/* 模态框全局样式 */
:deep(.app-detail-modal .ant-modal-content) {
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

:deep(.app-detail-modal .ant-modal-header) {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.95) 100%);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  padding: 20px 24px;
}

:deep(.app-detail-modal .ant-modal-body) {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.95) 100%);
  padding: 24px;
}

:deep(.app-detail-modal .ant-modal-close) {
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.8);
  transition: all var(--animation-duration-normal) var(--animation-easing);
}

:deep(.app-detail-modal .ant-modal-close:hover) {
  background: rgba(239, 68, 68, 0.1);
  transform: scale(1.1);
}

:deep(.app-detail-modal .ant-modal-close-x) {
  font-size: 16px;
  color: #6b7280;
  transition: color var(--animation-duration-normal) var(--animation-easing);
}

:deep(.app-detail-modal .ant-modal-close:hover .ant-modal-close-x) {
  color: #ef4444;
}
</style>
